package com.hhs.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhs.storage.bean.*;
import com.hhs.storage.dao.XmWorkDao;
import com.hhs.storage.service.XmUserClazzService;
import com.hhs.storage.service.XmUserWorkService;
import com.hhs.storage.service.XmWorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chx
 * @since 2024-10-20
 */
@Service
public class XmWorkServiceImpl extends ServiceImpl<XmWorkDao, XmWork> implements XmWorkService {

    @Resource
    private XmUserWorkService xmUserWorkService;
    @Override
    public Map<String, Object> addTeacher(InputParam inputParam) {
        String workId=inputParam.getId();
        String[] teacherIds=inputParam.getIds().split(",");
        QueryWrapper<XmUserWork> qw=new QueryWrapper<XmUserWork>();
        qw.in("user_id",teacherIds);
        qw.eq("work_id",workId);
        xmUserWorkService.remove(qw);
        for(String teacherId:teacherIds){
            XmUserWork xmUserWork=new XmUserWork();
            xmUserWork.setWorkId(workId);
            xmUserWork.setUserId(teacherId);
            xmUserWorkService.save(xmUserWork);
        }
        return ResponseInfo.success();
    }

    @Override
    public Map<String, Object> cancelTeacher(InputParam inputParam) {
        String workId=inputParam.getId();
        String[] teacherIds=inputParam.getIds().split(",");
        QueryWrapper<XmUserWork> qw=new QueryWrapper<XmUserWork>();
        qw.in("user_id",teacherIds);
        qw.eq("work_id",workId);
        xmUserWorkService.remove(qw);
        return ResponseInfo.success();
    }
}
